package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjWorkModuleWayService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkModuleWayVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单处理方式表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-16
 */
@Api(tags = "工单处理方式类接口")
@RestController
@RequestMapping("/work/moduleWay")
public class ZjWorkModuleWayController {
    @Resource
    private ZjWorkModuleWayService workModuleWayService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单模块-工单处理方式 - 新增或修改工单处理方式")
    @ApiOperation("新增或修改工单处理方式")
    @PostMapping("/{moduleId}/save")
    public Result save(HttpServletRequest request, @PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId,
                       @RequestBody @Valid WorkModuleWayVo workModuleWayVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workModuleWayService.save(custAccId, moduleId, workModuleWayVo);
        return Result.success(null == workModuleWayVo.getId()? "新增处理方式成功" : "修改处理方式成功");
    }

    @ApiOperation("获取处理方式列表")
    @PostMapping("/{moduleId}/getList")
    public Result getList(@PathVariable @ApiParam(value = "模块ID", required = true) Long moduleId, @RequestBody SelectVo selectVo) {
        return Result.success("获取处理方式列表成功").data(workModuleWayService.getList(moduleId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单处理方式 - 根据ID批量启用或禁用模块处理方式")
    @ApiOperation("根据ID批量启用或禁用模块处理方式")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "处理方式状态：false-启用，true-禁用") boolean status,
                          @RequestBody @ApiParam(value = "处理方式ID集合", required = true) List<Long> idList) {
        workModuleWayService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用处理方式成功" : "启用处理方式成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块-工单处理方式 - 根据ID批量删除模块处理方式")
    @ApiOperation("根据ID批量删除模块处理方式")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "处理方式ID集合", required = true)List<Long> idList) {
        workModuleWayService.deleteBatchById(idList);
        return Result.success("删除处理方式成功");
    }

}
